<?php
/**
 * (jobs)
 */
namespace App\Jobs\AmazonApi\SpApi;

use App\Logic\Amazon\Api\Report;
use App\Logic\Amazon\Api\RequiredConfig;
use App\Models\Basics\AmazonAccount;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class GrabParseReport implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * 任务最大尝试次数。
     *
     * @var int
     */
    public $tries = 2;

    /**
     * 任务运行的超时时间。
     *
     * @var int
     */
    public $timeout = 235;

    protected $account;
    protected $reportType;

    /**
     * GrabParseReport constructor.
     * @param AmazonAccount $account
     * @param $reportType
     */
    public function __construct(AmazonAccount $account, $reportType)
    {
        $this->account = $account;
        $this->reportType = $reportType;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $requiredConfig = RequiredConfig::getInit();
        $apiConfig = $requiredConfig->configuration($this->account->refresh_token,$this->account->aws_region);
        Report::apiDownloadDocument($apiConfig,$this->account,$this->reportType);
    }
}
